#include <filesystem>
#include <iostream>
#include <list>

using std::cout;
using std::endl;
using std::list;

template <typename Container>
void display(const Container &con)
{
    for(auto &elem : con)
    {
        cout << elem << "  ";
    }
    cout << endl;
}

void test()
{
    list<int> number = {1, 3, 7, 9, 6};
    list<int> other = {11, 66, 88, 22};
    display(number);
    display(other);

    cout << endl;
    auto it = number.begin();
    ++it;
    cout << "*it = " << *it << endl;
    number.splice(it, other);
    display(number);
    display(other);
    cout << "*it = " << *it << endl;

    cout << endl;
    list<int> other2 = {111, 777, 999, 888, 555, 333};
    auto cit = other2.end();
    --cit;
    cout << "*cit = " << *cit << endl;
    number.splice(it, other2, cit);
    display(number);
    display(other2);

    cout << endl;
    cit = other2.begin();
    ++cit;
    cout << "*cit = " << *cit << endl;
    auto cit2 = other2.end();
    --cit2;
    cout << "*cit2 = " << *cit2 << endl;
    number.splice(it, other2, cit, cit2);
    display(number);
    display(other2);

    cout << endl << "在同一个链表中进行splice操作" << endl;
    it = number.begin();
    ++it;
    cout << "*it = " << *it << endl;
    auto it2 = number.end();
    --it2;
    cout << "*it2 = " << *it2 << endl;
    number.splice(it, number, it2);
    display(number);

}

int main(int argc, char *argv[])
{
    test();
    return 0;
}


